package com.example.apisimpledy.controller;

import com.example.apisimpledy.entity.RestBean;
import com.example.apisimpledy.entity.dto.MyUser;
import com.example.apisimpledy.service.MyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
public class MyUserController {

    @Autowired
    private MyUserService myUserService;

    @PostMapping("/register")
    public String registerUser(
            @RequestParam String username,
            @RequestParam String password,
            @RequestParam String email) {
        try {
            MyUser registeredUser = myUserService.registerUser(username, password, email);
            return RestBean.success(registeredUser).asJsonString();
        } catch (RuntimeException e) {
            return RestBean.failure(400, e.getMessage()).asJsonString();
        }
    }
}
